
import React,{useState} from 'react'
import axios from "axios"
import { Toast} from "react-vant"
function Login(props) {
  const [phone,setphone ]=useState('')
  const [pwd,setpwd ]=useState('')
  const toLogin =()=>{
    let user={phone, pwd}
    axios.post("/toLogin",user).then((res=>{
      if(res.data.code==200){
        localStorage.setItem("user",JSON.stringify(user))
        props.history.go(-1)
      }else{
        Toast.fail(res.data.msg)
      }
    }))
  }
  return (
  
       <div>
        <p> 手机号：<input type="text" value={phone} onChange={(e)=>{
          setphone(e.target.value)
        }}/></p>
        <p>  密码： <input type="text" value={pwd} onChange={(e)=>{
          setpwd(e.target.value)
        }}/> </p>
       <button onClick={
        //  ()=>{
        //  console.log(phone,pwd)
        // }
        toLogin
       }>登录</button>
      </div>
 
  )
}

export default Login